﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true" CodeFile="TLHoaDonDauRa.aspx.cs" Inherits="TLHoaDonDauRa" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:UpdatePanel ID="up1" runat="server">
        <ContentTemplate>
            <div class="panel panel-success margin">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        Thiết lập hóa đơn đầu ra</h3>
                </div>
                <div class="panel-body">
                    <asp:DropDownList ID="drthang" runat="server" Width="150px" CssClass="form-control">
                        <asp:ListItem Text="Tháng 1" Value="1"></asp:ListItem>
                        <asp:ListItem Text="Tháng 2" Value="2"></asp:ListItem>
                        <asp:ListItem Text="Tháng 3" Value="3"></asp:ListItem>
                        <asp:ListItem Text="Tháng 4" Value="4"></asp:ListItem>
                        <asp:ListItem Text="Tháng 5" Value="5"></asp:ListItem>
                        <asp:ListItem Text="Tháng 6" Value="6"></asp:ListItem>
                        <asp:ListItem Text="Tháng 7" Value="7"></asp:ListItem>
                        <asp:ListItem Text="Tháng 8" Value="8"></asp:ListItem>
                        <asp:ListItem Text="Tháng 9" Value="9"></asp:ListItem>
                        <asp:ListItem Text="Tháng 10" Value="10"></asp:ListItem>
                        <asp:ListItem Text="Tháng 11" Value="11"></asp:ListItem>
                        <asp:ListItem Text="Tháng 12" Value="12"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="drnam" runat="server" Width="140px" CssClass="form-control">
                    </asp:DropDownList>
                    <asp:DropDownList ID="dlnhacungcap" runat="server" DataValueField="IDs" Width="250px"
                        CssClass="form-control" DataTextField="tenkhachhang">
                    </asp:DropDownList>
                    <asp:Button ID="btnXem" CssClass="btn btn-warning" runat="server" Text="Xem dữ liệu"
                        OnClick="btnXem_Click" />
                    <div style="width: 100%; margin-top: 5px; overflow: auto;" class="wrapper">
                        <div style="width: 100%; max-height: 200px;">
                            <asp:GridView ID="GV" runat="server" AutoGenerateColumns="false" BackColor="White"
                                ShowFooter="false" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
                                CellPadding="1" EmptyDataText="Không có dữ liệu nào" EnableModelValidation="True"
                                CssClass="form-control withall" Width="99%" OnSelectedIndexChanged="GV_SelectedIndexChanged">
                                <Columns>
                                    <asp:TemplateField HeaderText="Thiết lập" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="80px"
                                        ItemStyle-Width="80px">
                                        <ItemTemplate>
                                            <asp:ImageButton ID="lbTL" runat="server" Width="15px" Height="15px" ImageUrl="~/img/hd.jpg"
                                                CommandArgument='<%#Eval("thang")%>' Text="Thiết lập" CommandName="Select" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="thang1" ItemStyle-CssClass="padding" HeaderText="Tháng"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                          <asp:BoundField DataField="nam" ItemStyle-CssClass="padding" HeaderText="Năm"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundField DataField="NCC" ItemStyle-CssClass="padding" HeaderText="Khách hàng"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                                   
                                        <asp:BoundField DataField="tienhangkitruoc" ItemStyle-CssClass="padding" DataFormatString="{0:0,0}"
                                        HeaderText="Thành tiền hàng kì trước" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" />
                                        <asp:BoundField DataField="tienhangkinay" ItemStyle-CssClass="padding" DataFormatString="{0:0,0}"
                                        HeaderText="Thành tiền hàng kì này" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" />
                                         <asp:BoundField DataField="tienhang" ItemStyle-CssClass="padding" DataFormatString="{0:0,0}"
                                        HeaderText="Tổng thành tiền hàng" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" />
                                    <asp:BoundField DataField="loaihoadon" Visible="true" ItemStyle-CssClass="padding" HeaderText="Loại hóa đơn"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                    <asp:TemplateField Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lbTag" runat="server" Text='<%#Eval("ids") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <FooterStyle BackColor="White" ForeColor="#000066" Font-Bold="True" HorizontalAlign="Right" />
                                <HeaderStyle BackColor="White" Font-Bold="True" ForeColor="Black" Height="30px" />
                                <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                                <RowStyle BackColor="White" ForeColor="#000066" Height="30px" />
                                <SelectedRowStyle BackColor="Lavender" Font-Bold="false" />
                            </asp:GridView>
                        </div>
                    </div>
                    <table width="100%">
                        <tr>
                            <td>
                                Ngày tháng<br />
                                <asp:TextBox ID="txtngaythang"  CssClass="form-control" runat="server">
                                </asp:TextBox>
                                <cc1:CalendarExtender PopupPosition="BottomRight" ID="CalendarExtender1" runat="server"
                                    TargetControlID="txtngaythang" Format="dd/MM/yyyy">
                                </cc1:CalendarExtender>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtngaythang" ValidChars="/" />
                                <asp:RequiredFieldValidator ValidationGroup="Them" ID="RequiredFieldValidator5" runat="server"
                                    ControlToValidate="txtngaythang" ErrorMessage="Chọn ngày thanh toán" Display="None"
                                    Text="*"></asp:RequiredFieldValidator>
                            </td>
                            <td>
                                Khách hàng<br />
                                <asp:DropDownList ID="drnhacungcap" Enabled="false" CssClass="form-control" runat="server"
                                    DataTextField="NCC" DataValueField="IDs" AutoPostBack="true" OnSelectedIndexChanged="drnhacungcap_SelectedIndexChanged">
                                </asp:DropDownList>
                               
                            </td>
                            <td>
                                Thành tiền hàng<br />
                                <asp:TextBox ID="txtthanhtienhang" CssClass="form-control "  runat="server">
                                </asp:TextBox>
                            </td>
                            <td>
                                Thành tiền hóa đơn<br />
                                <asp:TextBox ID="txtthanhtienhoadon" CssClass="form-control" runat="server"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtthanhtienhoadon" ValidChars=",." />
                            </td>
                            <td>
                                % thuế<br />
                                <asp:TextBox ID="txtphantramthue" CssClass="form-control" runat="server">
                                </asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Số HĐ<br />
                                <asp:TextBox ID="txtsohd" CssClass="form-control" runat="server">
                                </asp:TextBox>
                            </td>
                            <td>
                                Mã số thuế<br />
                                <asp:TextBox ID="txtmasothue" CssClass="form-control" runat="server">
                                </asp:TextBox>
                            </td>
                            <td>
                                Chênh lệch phải trả<br />
                                <asp:TextBox ID="txtchenhlech" CssClass="form-control" runat="server">
                                </asp:TextBox>
                            </td>
                            <td>
                                <span style="margin-left: 5px;">
                                
                                    <br />
                                    <asp:CheckBox ID="ckChenhlech" Visible="true" runat="server"  Text="Đã trả chênh lệch"
                                         /></span>
                            </td>
                            <td>
                                Khách vãng lai<br />
                                <asp:TextBox ID="txtkhachvanglai" CssClass="form-control" runat="server"></asp:TextBox>
                               
                            </td>
                        </tr>
                        <tr>
                            <td colspan="6">
                                <span style="margin-left: 5px;">Nội dung hóa đơn:</span><br />
                                <asp:GridView ID="GV1" Visible="true" AutoGenerateColumns="false" runat="server"
                                    BackColor="White" Font-Size="14px" Width="100%" BorderColor="#CCCCCC" EmptyDataText="Không có dữ liệu nào"
                                    BorderStyle="None" BorderWidth="1px" CellPadding="3" EnableModelValidation="True"
                                    OnRowDeleting="gv_RowDeleting">
                                    <Columns>
                                        <asp:BoundField DataField="RowNumber" HeaderText="STT" HeaderStyle-Width="50px" HeaderStyle-HorizontalAlign="Center"
                                            ItemStyle-HorizontalAlign="Center"></asp:BoundField>
                                        <asp:TemplateField HeaderText="Nội dung" ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:TextBox ID="txtnoidung" runat="server" Width="98%"></asp:TextBox>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:CommandField HeaderText="Xóa" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="45px"
                                            ShowDeleteButton="True" DeleteText="Xóa" />
                                    </Columns>
                                    <FooterStyle BackColor="#6EA1C0" ForeColor="#000066" />
                                    <HeaderStyle BackColor="#6EA1C0" Font-Bold="True" ForeColor="White" Height="40px"
                                        HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
                                    <RowStyle ForeColor="#000066" Height="30px" />
                                    <SelectedRowStyle BackColor="#F1F1F1" Font-Bold="True" />
                                </asp:GridView>
                            </td>
                            <td>
                                <br />
                                <asp:DropDownList ID="drhinhthuckhongvat" CssClass="form-control" runat="server"
                                    Visible="false">
                                    <asp:ListItem Value="0" Text="Chọn hình thức thanh toán"></asp:ListItem>
                                    <asp:ListItem Value="1" Text="Ngân hàng"></asp:ListItem>
                                    <asp:ListItem Value="2" Text="Tiền mặt"></asp:ListItem>
                                    <asp:ListItem Value="3" Text="Đối trừ công nợ"></asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td>
                                <br />
                                <asp:DropDownList ID="drtkkhongvat" Visible="false" DataTextField="TaiKhoan" DataValueField="IDs"
                                    CssClass="form-control" runat="server">
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Button ID="btnAdd" ValidationGroup="add" runat="server" Text="Thêm nội dung"
                                    CssClass="btn btn-danger" OnClick="btnAdd_Click" />
                                <asp:Button ID="btnSave" ValidationGroup="Them" runat="server" Style="margin-left: 5px;"
                                    Text="Lưu lại" CssClass="btn btn-primary" OnClick="btnSave_Click" />
                                    <asp:Button ID="btncapnhat" runat="server" Text="Cập nhật" CssClass="btn btn-info"
                                    Visible="false" onclick="btncapnhat_Click" />
                                <asp:Button ID="btnCancel" runat="server" Text="Nhập mới" CssClass="btn btn-warning"
                                    OnClick="btnCancel_Click" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <br />
                                <asp:DropDownList ID="drdonvi" Visible="false" CssClass="form-control" runat="server"
                                    DataTextField="NCC" DataValueField="ids">
                                </asp:DropDownList>
                            </td>
                            <td>
                                <br />
                                <asp:TextBox ID="txtsoluong" Visible="false" CssClass="form-control" runat="server">
                                </asp:TextBox>
                            </td>
                            <td>
                                <br />
                                <asp:TextBox ID="txtdongia" Visible="false" CssClass="form-control" runat="server">
                                </asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <asp:ValidationSummary ID="ValidationSummary1" HeaderText="Bạn phải nhập các trường sau:"
                ShowMessageBox="true" ValidationGroup="Them" ShowSummary="false" EnableClientScript="true"
                runat="server" />
            <asp:ValidationSummary ID="ValidationSummary2" HeaderText="Bạn phải nhập các trường sau:"
                ShowMessageBox="true" ValidationGroup="Update" ShowSummary="false" EnableClientScript="true"
                runat="server" />
            <asp:HiddenField ID="hdID" runat="server" />
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <asp:HiddenField ID="hdTuNgay" runat="server" />
                        <asp:HiddenField ID="hdDenNgay" runat="server" />
            <asp:DropDownList ID="dlThang"  runat="server" Width="150px" AutoPostBack="true"
                            CssClass="form-control"  onselectedindexchanged="dlThang_SelectedIndexChanged"
                           >
                        </asp:DropDownList>
                        <asp:DropDownList ID="dlNam" 
                            runat="server" Width="110px" CssClass="form-control">
                        </asp:DropDownList>
                        <asp:TextBox ID="txtTuNgay" runat="server" 
                            placeholder="Từ ngày" Visible="true" Width="100px" CssClass="form-control"></asp:TextBox>&nbsp;
                        <asp:TextBox ID="txtDenNgay" runat="server" placeholder="Đến ngày" 
                            AutoPostBack="true" Visible="true" Width="100px" CssClass="form-control"></asp:TextBox>
                            
                        <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtTuNgay"
                            Format="dd/MM/yyyy">
                        </cc1:CalendarExtender>
                        <cc1:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="txtDenNgay"
                            Format="dd/MM/yyyy">
                        </cc1:CalendarExtender>
                        <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender9" runat="server" FilterType="Custom,Numbers"
                            TargetControlID="txtTuNgay" ValidChars="/-" />
                        <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender10" runat="server" FilterType="Custom,Numbers"
                            TargetControlID="txtDenNgay" ValidChars="/-" />
                    <asp:DropDownList ID="DropDownList3" runat="server" DataValueField="tenkhachhang" Width="250px"
                        CssClass="form-control" DataTextField="tenkhachhang">
                    </asp:DropDownList>
                    <asp:Button ID="Button1" CssClass="btn btn-warning" runat="server" 
                Text="Xem dữ liệu" onclick="Button1_Click"
                         />
            <div style="width: 100%; margin-top: 5px; overflow: auto;" class="wrapper">
                <div style="width: 100%; max-height: 200px;">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" BackColor="White"
                        BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="1" EmptyDataText="Không có dữ liệu nào"
                        EnableModelValidation="True" ShowFooter="false" CssClass="form-control withall"
                        Width="99%"  
                        onrowcommand="GridView1_RowCommand" >
                        <Columns>
                            <asp:TemplateField HeaderText="Xóa" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="50px"
                                ItemStyle-Width="50px">
                                <ItemTemplate>
                                    <asp:ImageButton ID="lbXoa" runat="server" Width="20px" Height="20px" ImageUrl="~/img/delete-24.png"
                                        OnClientClick="return confirm('Bạn chắc chắn muốn xóa ?')" CommandArgument='<%#Eval("IDs")%>'
                                        Text="Xóa" CommandName="Del" />
                                </ItemTemplate>
                            </asp:TemplateField>
                           <asp:TemplateField HeaderText="Sửa" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="50px"
                                    ItemStyle-Width="50px">
                                    <ItemTemplate>
                                        <asp:ImageButton ID="lbSua" runat="server" Width="15px" Height="15px" ImageUrl="~/img/edit.ico"
                                            CommandArgument='<%#Eval("IDs")%>' Text="Sửa" CommandName="Select" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            <asp:BoundField DataField="TenNCC" ItemStyle-CssClass="padding" HeaderText="Khách hàng"
                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                                <asp:BoundField DataField="khachvanglai" ItemStyle-CssClass="padding" HeaderText="Khách vãng lai"
                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                            <asp:BoundField DataField="ngaythang" ItemStyle-CssClass="padding" HeaderText="Ngày tháng"
                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                            <asp:BoundField DataField="thanhtienhang" ItemStyle-CssClass="padding" HeaderText="Thành tiền hàng"
                                DataFormatString="{0:0,0}" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" />
                            <asp:BoundField DataField="thanhtienhoadon" ItemStyle-CssClass="padding" HeaderText="Thành tiền hóa đơn"
                                HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" />
                            <asp:BoundField DataField="phantramthue" ItemStyle-CssClass="padding" HeaderText="% Thuế"
                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                            <asp:BoundField DataField="sohd" ItemStyle-CssClass="padding" HeaderText="Số hóa đơn"
                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                            <asp:BoundField DataField="masothue" ItemStyle-CssClass="padding" HeaderText="Mã số thuế"
                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                            <asp:BoundField DataField="chenhlechtra" ItemStyle-CssClass="padding" HeaderText="Chênh lệch trả"
                                HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                                
                        </Columns>
                        <FooterStyle BackColor="White" ForeColor="#000066" Font-Bold="True" HorizontalAlign="Left" />
                        <HeaderStyle BackColor="White" Font-Bold="True" ForeColor="Black" Height="30px" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <RowStyle BackColor="White" ForeColor="#000066" Height="30px" />
                        <SelectedRowStyle BackColor="Lavender" Font-Bold="false" />
                    </asp:GridView>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>


